package club.babyf.nativeai.common.exception;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

/**
 * ErrorCode.
 *
 * @author zhanglei.
 * @date 2025/2/21 15:44.
 * @description 错误码.
 */
@Getter
@ToString
@AllArgsConstructor
public enum ErrorCode {

    /**
     * 系统错误
     */
    SYSTEM_ERROR(1000, "系统错误", "Internal server error."),
    SQL_ERROR(1101, "数据库错误", "db server error."),

    /**
     * 业务错误
     */
    BUSINESS_ERROR(10000, "业务错误", "Business Error"),
    PARAMS_ERROR(10001, "参数错误", "Bad Request"),
    INVALID_REQUEST(10002, "无效的请求", "Invalid Request"),
    REQUEST_EXPIRED(10003, "请求已过期", "Request Expired"),
    NOT_FIND_YOU(10004, "找不到您的信息，请联系管理员limengzhu@wps.cn、yaobo1@wps.cn开通账号", "Not Find You"),

    INVALID_TOKEN(10101, "无效TOKEN", "Invalid token."),
    FORBIDDEN(100103, "禁止访问", "Forbidden."),
    NO_PERMISSION(100104, "未被授权访问", "No permission."),

    WPS_GET_COMPANY_TOKEN_ERROR(10201, "WPS-获取companyToken错误", "WPS get company token error."),
    WPS_GET_COMPANY_ERROR(10202, "WPS-获取company错误", "WPS get company error."),

    IN_PROGRESS(10301, "正在执行中", "In progress."),

    PREVIEW_API_CALL_ERROR(11001, "预览API调用错误", "Preview API call error."),
    ONES_API_ERROR(11000, "ONES API调用错误", "ONES API ERROR"),
    BUSINESS_OUT_SQL_NOTFOUND(21001, "未找到配置的SQL信息", "未找到配置的SQL信息"),
    BUSINESS_OUT_SQL_INCOMPLETE(21002, "配置的SQL信息不完整", "配置的SQL信息不完整"),
    CONDITION_NOT_MATCH(21003, "条件不匹配", "条件不匹配"),
    TRIGGER_NAME_EXIST(21004, "触发器名称重复", "触发器名称重复"),
    TRIGGER_DEL_ACTION_LINK(21005, "要删除的触发器有关联的动作，请先删除关联动作后，再删除触发器", "要删除的触发器有关联的动作，请先删除关联动作后，再删除触发器"),
    TRIGGER_EXEC_ACTION(21006, "调用执行器接口失败", "调用执行器接口失败"),
    TRIGGER_CRON_JOB_ERROR(21007, "调度中心创建JOB失败", "调度中心创建JOB失败"),
    TRIGGER_UPDATE_CRON_JOB_ERROR(21008, "调度中心更新JOB失败", "调度中心更新JOB失败"),
    TRIGGER_COPY_ERROR(21009, "复制失败", "复制失败"),
    PERM_SET_ERROR(21010, "权限设置失败", "权限设置失败"),
    CONN_ERROR(10110, "数据库连接失败", "数据库连接失败"),

    FLOW_ERROR(30000, "请求过于频繁，请稍后再试", "请求过于频繁，请稍后再试"),
    DEGRADE_ERROR(30001, "系统异常，请稍后再试", "系统异常，请稍后再试"),
    PARAM_FLOW_ERROR(30002, "请求参数过于频繁，请稍后再试", "请求参数过于频繁，请稍后再试"),
    SYSTEM_BLOCK_ERROR(30003, "系统被保护，请稍后再试", "系统被保护，请稍后再试"),
    AUTHORITY_ERROR(30004, "没有权限访问，请联系管理员", "没有权限访问，请联系管理员"),
    USER_LOGIN_ERROR(30005, "用户未登录", "用户未登录"),
    REQUEST_REPEAT_ERROR(30006, "请求重复", "Request repeat."),
    SIGNATURE_VERIFICATION_FAILED(10007, "验签失败", "Signature verification failed."),
    EXCEL_EXPORT_FAILED(10008, "导出失败", "Export failed."),
    ASSIGN_ROUTE_ERROR(40001, "业务系统分派路由异常,未能找到相关路由", "The business system dispatch route is abnormal, and the relevant route cannot be found."),

    FILE_DOES_NOT_EXIST(100010, "文件不存在", "FILE DOES NOT EXIST"),

    ;

    private final int code;
    private final String msg;
    private final String enMsg;

    public static ErrorCode valueOf(int errorCode) {
        ErrorCode[] values = values();
        for (ErrorCode item : values) {
            if (item.getCode() == errorCode) {
                return item;
            }
        }
        throw new IllegalArgumentException("No matching constant for [" + errorCode + "]");
    }

}
